//
//  ViewController.swift
//  learn-gl-es-swift
//
//  Created by LimitLiu on 2019/6/30.
//  Copyright © 2019 LimitLiu. All rights reserved.
//

import UIKit

class ViewController: UITableViewController {
    
    private lazy var viewModel: [String] = [
        "Ch2_1",
        "Ch2_2",
        "Ch2_3",
        "Ch3_1",
        "Ch3_2",
        "Ch3_3",
        "Ch3_4",
        "Ch3_5",
        "Ch3_6",
    ]
    
    private var table: UITableView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        table = UITableView(frame: view.frame)
        table.dataSource = self
        table.delegate = self
        view.addSubview(table)
        table.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
    }
}

extension ViewController {
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return viewModel.count
    }
    
    override func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = (tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)) as UITableViewCell
        cell.textLabel?.text = viewModel[indexPath.row]
        return cell
    }
    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let tmp = viewModel[indexPath.row]
        switch tmp {
        case "Ch2_1":
            navigationController?.pushViewController(Ch2_1Controller(), animated: true)
            break
        case "Ch2_2":
            navigationController?.pushViewController(Ch2_2Controller(), animated: true)
            break
        case "Ch2_3":
            navigationController?.pushViewController(Ch2_3Controller(), animated: true)
            break
        case "Ch3_1":
            navigationController?.pushViewController(Ch3_1Controller(), animated: true)
            break
        case "Ch3_2":
            navigationController?.pushViewController(Ch3_2Controller(), animated: true)
            break
        case "Ch3_3":
            navigationController?.pushViewController(Ch3_3Controller(), animated: true)
            break
        case "Ch3_4":
            navigationController?.pushViewController(Ch3_4Controller(), animated: true)
            break
        case "Ch3_5":
            navigationController?.pushViewController(Ch3_5Controller(), animated: true)
            break
        case "Ch3_6":
            navigationController?.pushViewController(Ch3_6Controller(), animated: true)
            break
        default:
            print("Failed to push view controller")
        }
    }
}
